<template>
  <div class="user-profile">
    <!-- 导航栏 -->
    <van-nav-bar
    class="page-nav-bar"
    title="个人信息"
    left-arrow @click-left="$router.back()" />
    <!-- /导航栏 -->
    <input @change="onChang" type="file" hidden ref='inputEf'>
    <van-cell title="头像" @click="$refs.inputEf.click()" is-link >
      <van-image
        class="avatar"
        fit="cover"
        round
        :src="user.photo"
      />
    </van-cell>
    <van-cell title="昵称" :value="user.name" is-link  @click="isStofales = true"/>
    <van-cell title="性别" @click="isStofalesUserEdiSex=true" :value="user.gender? '女': '男'" is-link />
    <van-cell title="生日" @click="isStofalesUserBirthday=true" :value="user.birthday" is-link />
    <van-popup v-model="isStofales" position="bottom" :style="{ height: '100%' }">
      <UserEdit v-if="isStofales" @on_right = "isStofales=false" v-model="user.name" @clickLeft="isStofales=false"/>
    </van-popup>
    <!-- 性别 -->
    <van-popup v-model="isStofalesUserEdiSex" position="bottom">
      <UserEdiSex v-if="isStofalesUserEdiSex" v-model="user.gender" @onCancel = "isStofalesUserEdiSex= false"/>
    </van-popup>
    <!-- 生日 -->
    <van-popup v-model="isStofalesUserBirthday" position="bottom">
      <UserBirthday v-if="isStofalesUserBirthday" v-model="user.birthday" @clicks= "isStofalesUserBirthday= false" />
    </van-popup>
    <!-- 头像 -->
    <van-popup v-model="isStofalesUserImg" position="bottom" :style="{ height: '100%' }">
      <UserEdiImg :imgURL="imgURL" v-if="isStofalesUserImg" @on-phto = "user.photo = $event" @clickTc = "isStofalesUserImg = false"/>
    </van-popup>
  </div>
</template>

<script>
import { getprofile } from '@/api/user.js'
import UserEdit from './cpmponents/UserEdit'
import UserEdiSex from './cpmponents/UserEdiSex'
import UserBirthday from './cpmponents/UserBirthday'
import UserEdiImg from './cpmponents/UserEdiImg'
export default {
  components: {
    UserEdit,
    UserEdiSex,
    UserBirthday,
    UserEdiImg
  },
  data () {
    return {
      user: {},
      isStofales: false,
      isStofalesUserEdiSex: false,
      isStofalesUserBirthday: false,
      isStofalesUserImg: false,
      imgURL: ''
    }
  },

  created () {
    this.getprofileClick()
  },

  methods: {
    async getprofileClick () {
      const res = await getprofile()
      this.user = res
    },
    onChang (e) {
      if (e.target.value === '') return
      this.isStofalesUserImg = true
      console.log(e.target)
      this.imgURL = URL.createObjectURL(e.target.files[0])
      e.target.value = ''
    }
  }
}
</script>

<style scoped lang='less'>
.user-profile {
  .avatar {
    width: 60px;
    height: 60px;
  }
  /deep/.van-nav-bar__arrow {
    color: #fff;
  }
}
</style>
